package com.lichong.controller;

import com.lichong.annotation.Limit;
import com.lichong.common.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class Test {

    /**
     * login接口在60秒内只能被一个ip地址访问5次
     */
    @RequestMapping("login")
    @Limit(key = "login", period = 60, count = 5, name = "登录接口", prefix = "limit")
    public ResponseVO login(@RequestParam("username") String username, @RequestParam("password") String password) {
        if ("admin".equals(username) && "12345".equals(password)) {
            return new ResponseVO().success().message("登录成功");
        } else {
            return new ResponseVO().fail().message("登录失败");
        }
    }
}
